<template>
  <div id="app">
    <form @submit.prevent="calculateBMI">
      <input type="text" v-model="patient.name" placeholder="姓名" />
      <input type="number" v-model.number="patient.age" placeholder="年龄" />
      <input type="number" step="0.01" v-model.number="patient.height" placeholder="身高(米)" />
      <input type="number" step="0.01" v-model.number="patient.weight" placeholder="体重(公斤)" />
      <textarea v-model="patient.medicalHistory" placeholder="病史"></textarea>
      <button type="submit">诊断</button>
    </form>

    <p>患者 {{ patient.name }} 的诊断结果：{{ diagnosis }}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      patient: {
        name: '',
        age: null,
        height: null,
        weight: null,
        medicalHistory: ''
      },
      diagnosis: ''
    }
  },
  methods: {
    calculateBMI() {
      if (!this.patient.height || !this.patient.weight) {
        this.diagnosis = '请填写完整的个人信息';
        return;
      }

      const bmi = this.patient.weight / Math.pow(this.patient.height, 2);
      let result;

      if (bmi <= 18.5) {
        result = '体重过轻';
      } else if (bmi > 18.5 && bmi <= 24.9) {
        result = '正常';
      } else if (bmi > 25 && bmi <= 29.9) {
        result = '超重';
      } else {
        result = '肥胖';
      }

      this.diagnosis = result;
    }
  }
}
</script>
